package com.hncc.dms.controller;

import com.hncc.dms.service.IDmsDiseService;
import com.hncc.dms.service.IDmsNonDrugService;
import com.hncc.dms.service.ISmsFrequentUsedService;
import com.hncc.sms.domain.SmsFrequentUsed;
import com.hncc.sms.domain.SmsFrequentUsedVo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 常用项管理Controller
 * 
 * @author ruoyi
 * @date 2020-08-29
 */
@RestController
@RequestMapping("/sms/frequent_used")
@Api(tags = "常用项管理接口")
public class SmsFrequentUsedController extends BaseController
{
    @Resource
    private ISmsFrequentUsedService smsFrequentUsedService;

    @Resource
    private IDmsDiseService dmsDiseService;

    @Resource
    private IDmsNonDrugService dmsNonDrugService;

    /**
     * 查询常用项管理列表
     */
    @ApiOperation(value = "条件分页查询常用项管理",httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('sms:frequent_used:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsFrequentUsed smsFrequentUsed)
    {
        startPage();
        List<SmsFrequentUsed> list = smsFrequentUsedService.selectSmsFrequentUsedList(smsFrequentUsed);
        return getDataTable(list);
    }

    /**
     * 导出常用项管理列表
     */
    @PreAuthorize("@ss.hasPermi('sms:frequent_used:export')")
    @Log(title = "常用项管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmsFrequentUsed smsFrequentUsed)
    {
        List<SmsFrequentUsed> list = smsFrequentUsedService.selectSmsFrequentUsedList(smsFrequentUsed);
        ExcelUtil<SmsFrequentUsed> util = new ExcelUtil<SmsFrequentUsed>(SmsFrequentUsed.class);
        return util.exportExcel(list, "frequent_used");
    }

    /**
     * 根据所属人查询成药草药
     */
    @GetMapping("/getDrug")
    public AjaxResult getDrug(){
        return AjaxResult.success(smsFrequentUsedService.getDrugIdListByUserId());
    }

    @GetMapping("/get")
    public TableDataInfo get(SmsFrequentUsedVo smsFrequentUsedVo){
        startPage();
        List<?> list = smsFrequentUsedService.selectSmsFrequentUsedById(smsFrequentUsedVo);
        return getDataTable(list);
    }

    /**
     * 新增常用项管理
     */
    @ApiOperation(value = "新增",httpMethod = "POST", notes = "新增常用项管理")
    @ApiImplicitParam(name = "smsFrequentUsed", value = "新增常用项管理", dataType = "SmsFrequentUsed")
    @PreAuthorize("@ss.hasPermi('sms:frequent_used:add')")
    @Log(title = "常用项管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(Integer type, Integer id)
    {

        return toAjax(smsFrequentUsedService.updateSmsFrequentUsed(type, id,"add"));
    }

    /**
     * 修改(删除)常用项管理
     */
    @ApiOperation(value = "修改", httpMethod = "PUT", notes = "修改常用项管理")
    @ApiImplicitParam(name = "smsFrequentUsed", value = "修改常用项管理", dataType = "SmsFrequentUsed")
    @PreAuthorize("@ss.hasPermi('sms:frequent_used:edit')")
    @Log(title = "常用项管理", businessType = BusinessType.UPDATE)
    @PutMapping("/upd")
    public AjaxResult edit(Integer type, Integer id)
    {
        return toAjax(smsFrequentUsedService.updateSmsFrequentUsed(type, id,"upd"));
    }

    /**
     * 删除常用项管理
     */
    @ApiOperation(value = "批量删除", httpMethod = "DELETE", notes = "根据ids删除常用项管理")
    @ApiImplicitParam(paramType = "path",name = "ids",value = "常用项管理id",dataType = "Long[]",required = true)
    @PreAuthorize("@ss.hasPermi('sms:frequent_used:remove')")
    @Log(title = "常用项管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsFrequentUsedService.deleteSmsFrequentUsedByIds(ids));
    }

    /**
     * 获取常用诊断ids
     * @return
     */
    @GetMapping("/getDise")
    public AjaxResult getDise(){
        String ids=smsFrequentUsedService.selectDiseIds();
        return AjaxResult.success(dmsDiseService.selectDmsDiseByIds(ids));
    }

    /**
     * 根据类型获取非药品常用项（检查，检验，处置）
     * @param type
     * @return
     */
    @GetMapping("/getFrequentUsedByType/{type}")
    public AjaxResult getFrequentUsedByType(@PathVariable Integer type){
        String ids=smsFrequentUsedService.selectNonDrugIds(type);
        return AjaxResult.success(dmsNonDrugService.selectNonDrugByIds(ids));
    }
}
